# coding=utf-8
# !/usr/bin/python3
import json
import os
import requests

cookies = {
    'JSESSIONID': '72F0EA33C4E94D2198E9CAFF0DB0F71E',
    'br-session-js-sdk': 'd593e6d5-da34-457e-9ab3-06f61cb10c30|1723384441245|1723384485475|16',
    'HOTEL_JSESSIONID': '6D45161868E6C43A52BE52723C81E696',
    'BIGipServerpool_hotel-api': '451084810.44326.0000',
    'altmobile': 'DxXXPhzlAgq9qK0vp92lDw' + os.getenv('$', ''),
    'otsBusiness': 'GoUPIhzlAgogOBpI4911BQ' + os.getenv('$', ''),
    'AlteonMobile': 'Hje5Zz/UAQreTc5Ze3O+Kw' + os.getenv('$', ''),
    'BIGipServernginxformobile': '2262368522.50215.0000',
}

headers = {
    'needlogin': 'true',
    'nbappid': '60000001',
    'nbversion': '5.8.2.52',
    'appv': '5.8.2.12',
    'tk': 'xQrpRajI6wyzGAT_eXJZkVumtViw-pa2MIHtRg27B2B0',
    'bbid': '2c0bb6fa-1345-3cd0-9ea7-edb2cec9ac6e',
    'fo': 'bvrijag7ojhezxs2h_Z-kBHaGX1Ni_B-ACz3v_dubsS_-vu2cmgDRiL4w0ms9REa0oWnUvkqXSJryJi6uKKv1sHJ7T-imNtrH48pV_2gGx5VQPto9R0CUumYlG8bEuB6sr3BCuwBbiEsqaekCP5yGnLUsSqQ0TEEMg-6yw',
    'user-agent': 'Dalvik/2.1.0 (Linux; U; Android 13; PJA110 Build/TP1A.220905.001)',
    'Platform': 'ANDROID',
    'AppId': '9101430221728',
    'WorkspaceId': 'product',
    'productVersion': '1.8.5.240509143035',
    'productId': '9101430221728_ANDROID',
    'did': 'TEMP-ZrcWDlQIJTkDAF8FTrk4UCtH',
    'clientId': '240810152601761|240810152601761',
    'TRACKERID': 'A8b38fac92acd0274151512b9263eead9',
    'signType': '0',
    'x-app-sys-Id': 'com.MobileTicket',
    # 'Cookie': 'JSESSIONID=72F0EA33C4E94D2198E9CAFF0DB0F71E; br-session-js-sdk=d593e6d5-da34-457e-9ab3-06f61cb10c30|1723384441245|1723384485475|16; HOTEL_JSESSIONID=6D45161868E6C43A52BE52723C81E696; BIGipServerpool_hotel-api=451084810.44326.0000; altmobile=DxXXPhzlAgq9qK0vp92lDw' + os.getenv('$', '') + '; otsBusiness=GoUPIhzlAgogOBpI4911BQ' + os.getenv('$', '') + '; AlteonMobile=Hje5Zz/UAQreTc5Ze3O+Kw' + os.getenv('$', '') + '; BIGipServernginxformobile=2262368522.50215.0000',
    'RpcId': '48',
    'TRACEID': 'TEMP-ZrcWDlQIJTkDAF8FTrk4UCtHnull_48',
    'Retryable2': '0',
    'Accept-Language': 'zh-Hans, zh-Hans',
    'Host': 'mobile.12306.cn',
}

params = {
    'operationType': 'com.cars.otsmobile.lcQueryDistance',
    'requestData': '[{"train_date":"2024-09-06","from_station_telecode":"QXE","to_station_telecode":"ZYE","purpose_codes":"00","middle_station":"","start_hour":"0000-2400","end_hour":"0000-2400","train_class":"QB#G#D#Z#T#K#QT#","wait_time":"","wait_max_time":"","same_station":"","sort_type":"1","randCode":"","train_nos":"","if_Show_ZD":"N","result_index":"0","can_query":"Y","query_type":"4","lc_ciphertext":"CxSwOGZDLZccFKSDS0y7YjbHy4vpJ2W9p5Ztdg==","isShowWZ":"Y","dfpStr":"","baseDTO":{"check_code":"5ac64bab93de3583195b9724e2fbea0d","device_no":"TEMP-ZrcWDlQIJTkDAF8FTrk4UCtH","h5_app_id":"60000001","h5_app_version":"5.8.2.52","hwv":"PJA110","mobile_no":"","os_type":"a","time_str":"20240901192430","user_name":"BugHero","version_no":"5.8.2.12"}}]',
    'ts': '1725189870792',
    'sign': 'cee23f647840654230de14db5d7ba782',
}

response = requests.get('https://mobile.12306.cn/otsmobile/app/mgs/mgw.htm', params=params, cookies=cookies, headers=headers).json()
formatted_response = json.dumps(response, ensure_ascii=False, indent=4)  # 美化输出
print(formatted_response)